package huajiu.com.dao;

import huajiu.com.domain.Test;



import org.hibernate.Query;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class TestDao {
	@Autowired
	private SessionFactory sessionFactory;
	
    public  Session getCurrentSession(){
    	return sessionFactory.getCurrentSession();
    }
    
    public  void save(Test test){
    	getCurrentSession().save(test);
    }
    public void query(){
    	Query query =(Query) getCurrentSession().createQuery("from test");
    	ScrollableResults sResults =query.scroll();
    	sResults.last();
    	int i = sResults.getRowNumber()+1;
    	System.out.println(i);
    	query.setFirstResult(0);
    	query.setMaxResults(3);
    }
}
